@Grapes([
@Grab("org.codehaus.geb:geb-core:latest.release"),
@Grab("org.seleniumhq.selenium:selenium-firefox-driver:latest.release"),
@Grab("org.seleniumhq.selenium:selenium-htmlunit-driver:latest.release")
])
import geb.Browser
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.htmlunit.HtmlUnitDriver

//def driver = new FirefoxDriver()
def driver = new HtmlUnitDriver()
def browser = new Browser(driver, "http://www.autotrader.co.uk/search/used/cars/honda/accord/postcode/w23qh/radius/100/fuel-type/petrol/maximum-age/up_to_5_years_old/sort/priceasc")
browser.go('http://www.autotrader.co.uk/search/used/cars/honda/accord/postcode/w23qh/radius/100/fuel-type/petrol/maximum-age/up_to_5_years_old/sort/priceasc')

assert browser.title =~ /Used HONDA ACCORD/

/* get all the cars */
def searchResults = browser.$(".searchResult")
println searchResults
searchResults.each {
	def price =  it.find(".offerPrice").text()
	def title =  it.find("a.title").text()
	def mileage = it.find("span.mileage").text()
	def transmission = it.find("span.transmission").text()
	def engine = it.find("span.engine").text()
	def fuel = it.find("span.fuel").text()
	def year = it.find(".advertIconsPrice h3").text()
}

driver.quit()

/**
 Things to do
 - name screenshot based on date
 - Use time to figure out what date to look at
 - email to hurst if finished
 */